<template>
  <PageBox :data="dataInfo" @searchBtn="getTbody" :maring="maring" :isRadio="isRadio" :isCheckbox="isCheckbox" @tableCheckboxBtn="tableCheckboxBtn" @tableRadioBtn="tableRadioBtn">
    <template #headR></template>
    <template #inStockBillStateName="{ row }">
      <el-tag type="danger" effect="dark" v-if="row.inStockFrom === 5">被红冲</el-tag>
      <ElTagBox :data="row.inStockBillState" :options="options.state" v-else />
    </template>
    <template #select_handInBillNo="{ row }">
      <PopoverTabel
        :title="row.handInBillNo"
        :width="1000"
        :thead="[
          {
            label: '缴库类型',
            prop: 'handInType',
            align: 'center',
            width: 100,
          },
          {
            label: '产品型号',
            prop: 'productSpecificationName',
            align: 'center',
            width: 100,
          },
          {
            label: '实缴数量',
            prop: 'handInQuantity',
            align: 'center',
            width: 100,
          },
          {
            label: '原库存使用',
            prop: 'originalQuantityUsage',
            align: 'center',
            width: 100,
          },
          {
            label: '包装数量',
            prop: 'packagingQuantity',
            align: 'center',
            width: 100,
          },
          {
            label: '缴库箱数',
            prop: 'handInBoxs',
            align: 'center',
            width: 100,
          },
          {
            label: '包装描述',
            prop: 'packageDescription',
            align: 'left',
            width: 220,
          },
          {
            label: '公斤数',
            prop: 'kilogramQuantity',
            align: 'center',
            width: 100,
          },
          {
            label: '备注',
            prop: 'handInMxRemark',
            align: 'center',
            width: null,
          },
        ]"
        @show="
          (table: any) => {
            switch (row.handInTypeName) {
              case '成品缴库':
                proxy.$api.ProductionBusniess.GetPageProductHandInBills({
                  pageIndex: 1,
                  pageSize: 1,
                  totalCount: 1,
                  queryDataBaseFiled: 'handInBillNo',
                  likeWords: row.handInBillNo,
                  onlySelf: 0,
                  isShowDisabled: -1,
                  orderByType: 0,
                  handInType: 0,
                  handInBillState: -1,
                  inStockState: -1,
                })
                  .then((res: any) => {
                    table.tbody =
                      res.list[0]?.detailList?.map((el: any) => ({
                        ...el,
                        handInType: el.handInType === 0 ? '发货' : '库存', //产品名称
                      })) || [];
                    table.loading = false;
                  })
                  .catch(() => {
                    table.tbody = [];
                    table.loading = false;
                  });
                break;
              default:
                proxy.$message('该单据未设置', 'error');
                table.tbody = [];
                table.loading = false;
                break;
            }
          }
        " />
    </template>
    <template #inStockBillNo="{ row }">
      <PopoverTabel
        :title="row.inStockBillNo"
        :width="1200"
        :thead="[
          {
            label: '缴库类型',
            prop: 'handInType',
            align: 'center',
            width: 100,
          },
          {
            label: '产品型号',
            prop: 'productSpecificationName',
            align: 'center',
            width: 100,
          },
          {
            label: '批次编号',
            prop: 'produceTaskBillNo',
            align: 'center',
            width: 100,
          },
          {
            label: '生产日期',
            prop: 'productionDate',
            align: 'center',
            width: 100,
          },
          {
            label: '库区库位',
            prop: 'storageAreaInfo',
            align: 'center',
            width: 100,
          },
          {
            label: '入库数量',
            prop: 'handInQuantity',
            align: 'center',
            width: 100,
          },
          {
            label: '备注',
            prop: 'handInMxRemark',
            align: 'left',
            width: null,
          },
        ]"
        :tbody="row.detailList">
        <template #productionDate="{ row }">
          {{ proxy.$day(row.productionDate) }}
        </template>
        <template #storageAreaInfo="{ row }">
          {{ `${row.warehouseAreaName}/${row.areaShelfName}` }}
        </template>
        <template #handInType="{ row }">
          {{ row.handInType === 1 ? '库存' : '发货' }}
        </template>
      </PopoverTabel>
    </template>
  </PageBox>
</template>
<script setup lang="ts">
const { proxy } = getCurrentInstance() as any;
import './pageCss.scss'; // 引入样式
import { useListComponent } from './pageTs'; // 引入逻辑
const props = withDefaults(
  defineProps<{
    isRadio?: boolean; //单选
    isCheckbox?: boolean; //多选
    maring?: number; //多选
  }>(),
  {},
);
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'tableRadioBtn', row: any): void;
  (event: 'tableCheckboxBtn', arr: any): void;
}>();
//多选数据
const tableCheckboxBtn = (arr: any) => {
  emit('tableCheckboxBtn', arr);
};
//单选数据
const tableRadioBtn = (row: any) => {
  emit('tableRadioBtn', row);
};
// 组件挂载后执行
onMounted(() => {
  getTbody();
});
const { dataInfo, getTbody, options } = useListComponent();
</script>
